module Enumerable
def group_by ( function )
hash = {}
for n in (0..self.size)
  if not hash[function(self[n])] == 0
    list = []
    list.append(self[n])
    hash[function(self[n])] = list
  else
    list = hash[function(self[n])]
    list.append(self[n])
    hash[function(self[n])] = list
  end
end
print hash
end
end

a = %w(apple banana cherry alice bob carol alpha bravo charlie)
a.group_by { |x| x[0,1].to_s }
print a.size